/*
 * @Author: “ygnnli” “1585923072@qq.com”
 * @Date: 2024-08-02 11:36:43
 * @LastEditors: “ygnnli” “1585923072@qq.com”
 * @LastEditTime: 2024-08-02 20:34:57
 * @FilePath: /110/42/Main.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "ThreePool.hpp"
#include <iostream>
#include <string>
#include <memory>
#include "Log.hpp"
#include <unistd.h>
#include "Task.hpp"
#include <ctime>

int main()
{
    // EnableFile(); // 启用文件日志
    // // 自动获取文件名和所在行数
    // LOG(DEBUG, "hello world");
    // LOG(DEBUG, "hello: %s %d, %f", "world", 10, 3.14);

    EnableScreen(); // 启用屏幕日志
    // EnableFile(); // 启用文件日志
    srand(time(nullptr) ^ getpid());
    std::unique_ptr<ThreePool<Task>> tp = std::make_unique<ThreePool<Task>>();
    // std::unique_ptr<ThreePool<int>> tp(new ThreePool<int>());

    tp->InitThreadPool();
    tp->Start();

    // 任务个数
    int tasknum = 10;
    while (tasknum)
    {
        int a = rand() % 10 + 1;
        usleep(1000);
        int b = rand() % 5 + 1;
        Task t(a, b);
        LOG(INFO, "main thread push task: %s", t.DebugToString().c_str());
        tp->Enqueue(t);
        sleep(1);
        tasknum--;
    }

    tp->Stop();

    // tp->Enqueue();

    tp->Wait();

    return 0;
}